package com.baseproject.imageload;

import android.widget.ImageView;

import java.io.File;


/**
 * Created by Anthony on 2016/3/3.
 * Class Note:
 * encapsulation of ImageView,Build Pattern used
 */
public class ImageLoaderConfigPara {
    private int type;  //类型 (大图，中图，小图)
    private String url; //需要解析的url
    private File file;//本地图片文件
    private int placeHolder; //当没有成功加载的时候显示的图片
    private ImageView imgView; //ImageView的实例
    private int wifiStrategy;//加载策略，是否在wifi下才加载

    private ImageLoaderConfigPara(Builder1 builder1) {
        this.type = builder1.type;
        this.url = builder1.url;
        this.file = builder1.file;
        this.placeHolder = builder1.placeHolder;
        this.imgView = builder1.imgView;
        this.wifiStrategy = builder1.wifiStrategy;
    }

    public int getType() {
        return type;
    }

    public String getUrl() {
        return url;
    }

    public File getFile() {
        return file;
    }

    public int getPlaceHolder() {
        return placeHolder;
    }

    public ImageView getImgView() {
        return imgView;
    }

    public int getWifiStrategy() {
        return wifiStrategy;
    }

    private static abstract class BaseBuilder {
        protected int type;
        protected int placeHolder; //网络加载图片失败时的默认图片
        protected int wifiStrategy;

        /**
         * 网络加载图片时使用url，本地加载图片时使用file
         */
        protected String url;
        protected File file;

        protected ImageView imgView;
    }

    public static class Builder1 extends BaseBuilder {

        public Builder1() {
            this.type = ImageLoaderUtil.PIC_SMALL;
//            this.placeHolder = R.drawable.drawable_loading_anim;
            this.wifiStrategy = ImageLoaderUtil.LOAD_STRATEGY_NORMAL;

            this.url = "";
            this.imgView = null;
            this.file = null;
        }

        public Builder1 type(int type) {
            this.type = type;
            return this;
        }

        public Builder1 url(String url) {
            this.url = url;
            return this;
        }

        public Builder1 file(File file) {
            this.file = file;
            return this;
        }

        public Builder1 placeHolder(int placeHolder) {
            this.placeHolder = placeHolder;
            return this;
        }

        public Builder1 imgView(ImageView imgView) {
            this.imgView = imgView;
            return this;
        }

        public Builder1 strategy(int strategy) {
            this.wifiStrategy = strategy;
            return this;
        }

        public ImageLoaderConfigPara build() {
            return new ImageLoaderConfigPara(this);
        }

    }
}
